﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Web.Util;

namespace StudentManage.Common
{
    /// <summary>
    /// 功能简介：定制的验证类
    /// 创建人：彭陈旺
    /// 创建时间：2013-4-27
    /// </summary>
    public class ZxxkRequestValidator : RequestValidator
    {
        static string[] UnSafeStr = new string[] { "<script","<iframe","<frame" };
        public ZxxkRequestValidator()
        {
        }
        protected override bool IsValidRequestString(HttpContext context, string value, RequestValidationSource requestValidationSource, string collectionKey, out int validationFailureIndex)
        {
            //block script tags
            int idx =-1;
            string sValue = value.ToLower();
            for (int i = 0; i < UnSafeStr.Length; i++)
            {
                idx = sValue.IndexOf(UnSafeStr[i]);
                if (idx > -1)
                    break;
            }
            if (idx > -1)
            {
                validationFailureIndex = idx;
                return false;
            }
            else
            {
                validationFailureIndex = 0;
                return true;
            }
        }
    }
}
